123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- "use client";
- import React, {useState} from 'react'
- import { ServiceTypes } from "@/api/customservice";
- import { Link } from "@/i18n";
- import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore";
- import { useSocialStore } from "@/stores/useSocials";
- import { Badge } from "antd-mobile";
- import { useTranslations } from "next-intl";
- import { FC, useEffect } from "react";
- import PopupHby from "@/app/[locale]/(TabBar)/(entire)/promo/PopupHby";
- import { redPacketApi,lredPacketApi } from "@/api/promo";
- import { getToken } from "@/utils/Cookies";
- import { getUserMoneyApi } from "@/api/user";
- import { useRequest } from "ahooks";
- interface Props {
- services: ServiceTypes[];
- socials: ServiceTypes[];
- }
- const ServiceWidget: FC<Props> = (props) => {
- const token = getToken();
- const [isShowRedPacket, setIsShowRedPacket] = useState<any>(false);
- const [isShowRedIcon,setIsShowRedIcon] = useState(false)
- const { services, socials } = props;
- const defaultService = services.find((item) => item.is_suspend === 1);
- const newServices = services.filter((item) => item.is_suspend !== 1);
- const setSocials = useSocialStore((state) => state.setSocials);
- useEffect(() => {
- // 数据存储,侧边栏使用
- setSocials(socials);
- }, []);
- const t = useTranslations("HomePage");
- const { unread } = useGlobalNoticeStore((state) => ({
- unread: state.unread,
- }));
- const getRedPacketInfo =async()=>{
- try{
- let redPacketInfo:any
- let actList:any = []
- if(token){
- redPacketInfo =await lredPacketApi()
- actList = redPacketInfo.data?.red_packets || []
- }else{
- redPacketInfo =await redPacketApi()
- actList = redPacketInfo.data || []
- }
-
- // 是否有已开始但是没领过的红包
- let isHasStartAct = actList.filter((aItem:any)=>{
- return !!aItem.is_start && !aItem.is_receive
- })
- let isShowRed = isHasStartAct.length>0
- setIsShowRedIcon(isShowRed)
-
- }catch(error){
- console.log('redPacketInfo===>error:',error)
- }
-
- }
- // 红包雨轮询
- useRequest(getRedPacketInfo, {
- pollingInterval: 180000,
- pollingErrorRetryCount: 1,
- pollingWhenHidden: false,
- onSuccess: (data) => {
- console.log('data',data)
- },
- });
- return (
- <>
- {/* 红包雨icon */}
- {
- isShowRedIcon && (
- <div
- className={
- "flex h-[0.54rem] w-[0.54rem] items-center" +
- " absolute bottom-[2.04rem] right-[0.12rem] z-50 justify-center cursor-pointer"
- }
- >
- <img
- className={"h-[0.3889rem] w-[0.3889rem]"}
- src='/hby/red-icon.png'
- onClick={()=>{setIsShowRedPacket(true)}}
- />
- </div>
- )
- }
-
- {/* 红包弹窗 */}
- {
- isShowRedPacket && (<PopupHby onClose={()=>{setIsShowRedPacket(false)}} />)
- }
- {defaultService && (
- <Link
- href={defaultService.url}
- className={
- "flex h-[0.54rem] w-[0.54rem] items-center justify-center rounded-[50%]" +
- " absolut absolute bottom-[0.84rem] right-[0.12rem] z-50 bg-gradient-to-b from-[#ff6a01] to-primary-color"
- }
- target={"_blank"}
- >
- <img
- className={"h-[0.3889rem] w-[0.3889rem]"}
- src={defaultService.icon_url}
- ></img>
- </Link>
- )}
- <Link
- href={"/notification"}
- className={
- "flex h-[0.54rem] w-[0.54rem] items-center" +
- " absolute bottom-[1.44rem] right-[0.12rem] z-50 justify-center rounded-[50%] bg-gradient-to-b from-[#0575e6] to-[#00f260]"
- }
- >
- <Badge content={!!unread ? unread : null} style={{ "--top": "12px" }}>
- <i className={"iconfont icon-duanxinguanli text-[0.3rem] text-[#fff]"}></i>
- </Badge>
- </Link>
- <div className={`grid grid-cols-${newServices.length >= 5 ? 5 : newServices.length}`}>
- {newServices.map((service, index) => {
- return (
- <Link
- key={index}
- href={service.url}
- target={"_blank"}
- className="bg-white m-[0.05rem] h-[0.3889rem] w-[0.3889rem] rounded"
- >
- <img
- className={"h-[0.3889rem] w-[0.3889rem]"}
- src={service.icon_url}
- ></img>
- </Link>
- );
- })}
- </div>
- <div className={"text-[#ff6a01]"}>{t("Service")}</div>
- {/*share*/}
- <div className={"my-[0.2rem] text-[0.08rem] text-[#adadad]"}>{t("Share")}</div>
- <div className={`grid grid-cols-${socials.length >= 5 ? 5 : socials.length}`}>
- {socials.map((service, index) => {
- return (
- <Link
- key={index}
- href={service.url}
- target={"_blank"}
- className="bg-white m-[0.05rem] h-[0.3889rem] w-[0.3889rem] rounded"
- >
- <img
- className={"h-[0.3889rem] w-[0.3889rem]"}
- src={service.icon_url}
- ></img>
- </Link>
- );
- })}
- </div>
- </>
- );
- };
- export default ServiceWidget;
|